import { WindowInfo } from './window'
import {
  VuexModule,
  Module,
  Mutation,
  Action,
  RegisterOptions
} from 'vuex-class-modules'
import { store } from '../store'

export interface WindowInfo {
  innerWidth: number
  innerHeight: number
}

@Module
class WindowModule extends VuexModule {
  window: WindowInfo

  constructor(options: RegisterOptions) {
    super(options)
    this.window = {
      innerWidth: window.innerWidth,
      innerHeight: window.innerHeight
    }
  }

  @Mutation
  SetSize() {
    this.window = {
      innerHeight: window.innerHeight,
      innerWidth: window.innerWidth
    }
  }

  get innerWidth() {
    return this.window.innerWidth
  }

  get innerHeight() {
    return this.window.innerHeight
  }
}

export const windowModule = new WindowModule({ store, name: 'window' })
